package com.resume.aipeople.dto;

import com.resume.aipeople.entity.ChatMessage;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ChatMessageDTO {
    private Long id;
    private String sessionId; // 会话ID，而不是整个session对象
    private String messageType; // USER, ASSISTANT
    private String content;
    private String audioUrl;
    private String skillUsed;
    private String emotionDetected;
    private Long responseTime;
    private LocalDateTime createdAt;
    
    public ChatMessageDTO(ChatMessage chatMessage) {
        this.id = chatMessage.getId();
        // 获取sessionId，避免延迟加载
        if (chatMessage.getSession() != null) {
            this.sessionId = chatMessage.getSession().getSessionId();
        }
        this.messageType = chatMessage.getMessageType() != null ? 
            chatMessage.getMessageType().name() : null;
        this.content = chatMessage.getContent();
        this.audioUrl = chatMessage.getAudioUrl();
        this.skillUsed = chatMessage.getSkillUsed();
        this.emotionDetected = chatMessage.getEmotionDetected();
        this.responseTime = chatMessage.getResponseTime();
        this.createdAt = chatMessage.getCreatedAt();
    }
}

